<template>
  <el-dialog :title="dialogTit" :visible.sync="projectbuildingVisible" :close-on-click-modal="false"
             :append-to-body="true" :modal-append-to-body="false">
    <div class="mod-prod-info">
      <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
        <el-form-item label="楼栋名称" prop="bname">
          <el-input v-model="dataForm.bname" placeholder="参数名"></el-input>
        </el-form-item>
        <el-form-item label="总套数" prop="totalsets">
          <el-input v-model="dataForm.totalsets" placeholder="参数值"></el-input>
        </el-form-item>
        <el-form-item label="可售套数" prop="presalesets">
          <el-input v-model="dataForm.presalesets" placeholder="可售套数"></el-input>
        </el-form-item>
        <el-form-item label="已售套数" prop="saledsets">
          <el-input v-model="dataForm.saledsets" placeholder="已售套数"></el-input>
        </el-form-item>
        <el-form-item label="层高" prop="layers">
          <el-input v-model="dataForm.layers" placeholder="层高"></el-input>
        </el-form-item>
        <el-form-item label="备注" prop="biz">
          <el-input v-model="dataForm.biz" placeholder="备注"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary"
                     @click="dataFormSubmit()">确定</el-button>
        </el-form-item>
      </el-form>
    </div>
  </el-dialog>

</template>
<script>
import { getUUID } from '@/utils'
import {Debounce} from "@/utils/debounce";
export default {
  name:'projectbuilding',
  data(){
    return {
      dialogTit: '维护楼栋信息',
      projectbuildingVisible : false,
      dataForm: {
        id: '',
        pid: '',
        bname: '',
        totalsets: '',
        presalesets: '',
        saledsets: '',
        layers: '',
        state: '',
        biz: ''
      },
      dataRule: {
        bname: [
          { required: true, message: '楼栋名称不能为空', trigger: 'blur' },
          { pattern: /\s\S+|S+\s|\S/, message: '请输入正确的楼栋名称', trigger: 'blur' }
        ]
      }
    }
  },
  methods :{
    init(pid){
      this.projectbuildingVisible = true
      this.dataForm.pid=pid
      this.$nextTick(() => {
        this.$refs['dataForm'].resetFields()
      })
    },
    dataFormSubmit: Debounce(function () {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.$http({
            url: this.$http.adornUrl(`/project/saveProjectBuilding`),
            method: 'post',
            data: this.$http.adornData({
              'id': getUUID(),
              'bname': this.dataForm.bname,
              'totalsets': this.dataForm.totalsets,
              'presalesets': this.dataForm.presalesets,
              'saledsets': this.dataForm.saledsets,
              'layers': this.dataForm.layers,
              'state': this.dataForm.state,
              'biz': this.dataForm.biz
            })
          }).then(({data}) => {
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
                this.projectbuildingVisible = false
                this.$emit('refreshBuilding')
              }
            })
          })
        }
      })
    })
  }

}
</script>
